//
//  HotScrollView.m
//  BiDongComic
//
//  Created by 吴炳毅 on 16/3/16.
//  Copyright © 2016年 BestRiven. All rights reserved.
//

#import "HotScrollView.h"
#import "ComicGridModel.h"
#import <SDWebImage/SDWebImageManager.h>
#import <UIImageView+WebCache.h>




@implementation HotScrollView

- (instancetype)initWithFrame:(CGRect)frame arr:(NSArray *)arrAllData index:(NSIndexPath *)indexpath imageCount:(NSInteger)count arrCount:(NSArray *)arrCount
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addAllViews:arrAllData index:indexpath imageCount:count arrCount:arrCount];
        
     

    }
    return self;
}


//添加所有视图   参数含义:所有数据/下标/每组图片数量
- (void)addAllViews:(NSArray *)arrAllData  index:(NSIndexPath *)indexpath imageCount:(NSInteger)count arrCount:(NSArray *)arrCount{
    self.backgroundColor = [UIColor whiteColor];
    self.contentSize = CGSizeMake(count*130+10, 0);
    self.showsHorizontalScrollIndicator = YES;
    self.showsHorizontalScrollIndicator = NO;
    NSInteger countLasttemp = 0;
    for (int i = 0; i < arrCount.count; i++) {
        if (indexpath.row == i) {
            break;
        }
        countLasttemp += [arrCount[i] integerValue];
    }
    //添加图片
    for (int i = 0; i < count; i++) {
        UIImageView *imV = [[UIImageView alloc]initWithFrame:CGRectMake(130*i+10, 30, 120, 150)];
        imV.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1]];
        imV.tag = 100+i;
        [self addSubview:imV];
        //图片文字背景图
        UIView *imVBackGrand = [[UIView alloc]initWithFrame:CGRectMake(0, imV.frame.size.height - 50, imV.frame.size.width, 50)];
        imVBackGrand.backgroundColor = [UIColor blackColor];
        imVBackGrand.alpha = 0.6;
        [imV addSubview:imVBackGrand];
        //漫画名称
        UILabel *lableTitle  = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 130, 20)];
        lableTitle.textColor = [UIColor whiteColor];
        lableTitle.font = [UIFont systemFontOfSize:12];
        ComicGridModel *m = arrAllData[countLasttemp+i];
        lableTitle.text = m.title;
        [imV sd_setImageWithURL:[NSURL URLWithString:m.vertical_image_url]];
        [imVBackGrand addSubview:lableTitle];
        //作者名称
        UILabel *lableEditor = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, 130, 20)];
        lableEditor.textColor = [UIColor whiteColor];
        lableEditor.font = [UIFont systemFontOfSize:11];
        lableEditor.text = m.user[@"nickname"];
        [imVBackGrand addSubview:lableEditor];
    }
}


@end
